<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div style="font-size: 12px" id="messages"></div>
    <script>
      const eventSource = new EventSource("http://localhost:3333/sse");

      eventSource.onmessage = function (event) {
        const msg = document.createElement("p");
        msg.textContent =
          "Message: " +
          JSON.parse(event.data).map((e) => e.nickname) +
          Date.now();
        console.log(JSON.parse(event.data));
        document.getElementById("messages").appendChild(msg);
      };

      eventSource.onerror = function (err) {
        console.error("EventSource failed:", err);
      };
    </script>
  </body>
</html>
